package hotciv.common;

import java.util.Map;

import hotciv.framework.GameConstants;
import hotciv.framework.Position;
import hotciv.strategies.LayoutStrategy;

import thirdparty.ThirdPartyFractalGenerator;

public class FractaleGeneratorAdapter implements LayoutStrategy {

	private Map<Position, TileImpl> tiles;
	private Map<Position, CityImpl> cities;
	private Map<Position, UnitImpl> units;
	private Map<Position, Integer> cityProductionStashes;
	
	/**
	 * Uses the Third Party Fractal Generator to create the MAP with tiles. The client has to create the units and cities itself.
	 * Precondition: Cities and units are placed on valid ground.
	 * 
	 * @param tpfg - the Third Party Fractal Generator from which to create the tiles MAP
	 * @param cities - the city MAP
	 * @param units - the unit MAP
	 * @param cityProductionStashes - the city production MAP
	 */
	public FractaleGeneratorAdapter(ThirdPartyFractalGenerator tpfg, Map<Position, CityImpl> cities, Map<Position, UnitImpl> units, Map<Position, Integer> cityProductionStashes) {
		
		this.cities = cities;
		this.units = units;
		this.cityProductionStashes = cityProductionStashes;
		
		String [] layout = new String [GameConstants.WORLDSIZE];
		for( int row = 0; row < GameConstants.WORLDSIZE; row++) {
			String rowstring = "";
			for( int column = 0; column < GameConstants.WORLDSIZE; column++) {
				rowstring += tpfg.getLandscapeAt(row , column);
			}
			layout[row] = rowstring;
		}
		tiles = WorldCreator.createWorldFromStringArray(layout);
	}
	
	@Override
	public Map<Position, CityImpl> getCities() {
		return cities;
	}

	@Override
	public Map<Position, Integer> getCityProductionStashes() {
		return cityProductionStashes;
	}

	@Override
	public Map<Position, UnitImpl> getUnits() {
		return units;
	}

	@Override
	public Map<Position, TileImpl> getTiles() {
		return tiles;
	}

}
